<?php
namespace App\Libs\ZiNiao;

use App\Libs\ZiNiao\Common\OpenClient;
use App\Libs\ZiNiao\Request\UserTokenRequest;
use Exception;
class RequireUserToken
{
    /**
     * 获取用户凭证接口
     * @param OpenClient $openClient
     * @param $bizContent ['userCode' => "XXXXXX"]
     * @return mixed
     */
    public function getUserToken(OpenClient $openClient,$bizContent)
    {
        $request = new UserTokenRequest();
        $request->setBizContent(json_encode($bizContent));
        $result = $openClient->execute($request);// 发送请求
        $result_decode = json_decode($result);
        if (($result_decode->code === 0 or $result_decode->code === '0') and !isset($result_decode->sub_code)) {
            return $result_decode->data;
        }else {
            report(new Exception('UserToken失败:' . $result,214));
            die(0);
        }
    }

}
